<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/23
 * Time: 13:33
 */

namespace Admin\Model;


class FileModel extends \Think\Model{



    protected $_auto=array(
        array('auditor_time','time',2,'function'),
    );


    function all_file($list){
        $file_sql=$this
            ->field('*,dx_file.id as file_id')
            ->join('left join dx_category c on c.id=file_category_id')
            ->join('left join dx_user u on u.id=user_id')
            ->order('dx_file.create_time desc')
            ->page($_GET['p'].','.$list)
            ->select();
        return $file_sql;
    }


    function auditor_file($list){
        $file_sql=$this
            ->field('*,dx_file.id as file_id')
            ->join('left join dx_category c on c.id=file_category_id')
            ->join('left join dx_user u on u.id=user_id')
            ->where('auditor=%d','0')
            ->order('dx_file.create_time desc')
            ->page($_GET['p'].','.$list)
            ->select();
        return $file_sql;

    }


    function once_file($id){
        $file_sql =$this
            ->field('*,dx_file.id as file_id')
            ->join('left join dx_category c on c.id=file_category_id')
            ->join('left join dx_user u on user_id=u.id')
            ->where('dx_file.id=%d ',array($id))
            ->order('dx_file.create_time desc')
            ->find();

        $file_sql['tag']=M('file_tag')->where('file_id=%d',$id)->select();
        $file_sql['content'] =html_entity_decode($file_sql['content']);


        return  $file_sql;
    }


    function search_file($list,$name){

    $like['name']=array('like','%'.$name.'%');
        $file_sql=$this
            ->field('dx_file.id as file_id,nickname,name,file_img_url,category_name,auditor,dx_file.create_time create_time')
            ->join('left join dx_category c on c.id=file_category_id')
            ->join('left join dx_user u on u.id=user_id')
            ->where($like)
            ->order('dx_file.create_time desc')
            ->page($_GET['p'].','.$list)
            ->select();
        return $file_sql;
    }
}